// pages/company_shop/company_shop.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    /**      * 页面配置      */
    winWidth: 0, winHeight: 0,
    // tab切换   
    height: 0,
    currentTab: 1,
    gryhq: [],
    sjyhq: [

      { id: 0, src: 'https://tanghuzhao.cn/Public/images/sjhd1.png' }, 
    ],
    gryhq: [{ id: 0, src: 'https://tanghuzhao.cn/Public/images/gryhq5.png' }, { id: 1, src: 'https://tanghuzhao.cn/Public/images/gryhq7.png' }, { id: 2, src: 'https://tanghuzhao.cn/Public/images/gryhq18.png' }, { id: 3, src: 'https://tanghuzhao.cn/Public/images/gryhq25.png' }, { id: 4, src: 'https://tanghuzhao.cn/Public/images/gryhq25.png' }, { id: 5, src: 'https://tanghuzhao.cn/Public/images/gryhq5.png' }, { id: 6, src: 'https://tanghuzhao.cn/Public/images/gryhq7.png' }, { id: 7, src: 'https://tanghuzhao.cn/Public/images/gryhq5.png' }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.globalData.froms == 'user') {
      wx.setNavigationBarColor({
        frontColor: 'white',
        backgroundColor: '#e93d3b',
      })
    } else {
      wx.setNavigationBarColor({
        frontColor: 'white',
        backgroundColor: '#e93d3b',
      })
    }
    var count1 = this.data.sjyhq.length
    var count2 = this.data.gryhq.length
    this.setData({
      height1: 190*count1,
      height2: 178*parseInt(count2/2),
    })
      this.yjqList();
  },

  yjqList:function(e){
        var that = this
    wx.request({
      url: app.d.hostUrl + '/Api/BSale/sjindex',
      method: 'post',
      data: {
        uid: app.d.userId
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        //获取时间戳,确定失效优惠券
        var sale = res.data.sale;
         console.log(sale);
         that.setData({
              gryhq: sale,
            })
      },
      fail: function (e) {
        wx.showToast({
          title: '网络不给力！',
          duration: 2000
        });
      },
    })
  },
  goShopping:function(e){
    var that = this
    var news_id=e.target.id
      wx.request({
          url: app.d.ceshiUrl + '/Api/BSale/addyhq',
          method: 'post',
          data: {
            uid: app.d.userId,
            vid: e.currentTarget.dataset.proid
          },
          header: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res);
            var data = res.data;
            if (data.status == 1) {
                
                wx.showToast({
                  title: '领取成功',
                  icon: 'success',
                  duration: 1000
                });
                that.yjqList();

              
            } else {
              wx.showToast({
                title: data.msg,
                duration: 2000
              });
            }
          },
          fail: function () {
            wx.showToast({
              title: '网络不给力！',
              duration: 2000
            });
          }
   });
  },
  getMore:function(e){
      wx.showToast({
          title: '没有更多数据',
          icon: 'success',
          duration: 1000
                });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '',
      path: '',
      success: function (res) {
        // 分享成功
      },
      fail: function (res) {
        // 分享失败
      }
    }
  },
  /**     * 滑动切换tab     */
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  /**    * 点击tab切换    */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) { return false; }
    else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
})